home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * App.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS_isModuleInitialized("IS.NOF.HTML.App"))
- {
-
- /****h* NOF_JavaScript_Library/NOF.HTML.App
- *
- * NAME
- * NOF.HTML.App
- *
- * DESCRIPTION
- * Base class for all HTML applications.
- *
- ****/
- /**
- * Constructor
- * @param _name - initial name of the HTML application. Can be null.
- * @param _resourcePath - initial path to resources
- * @param _locale - intial locale
- **/
- function NOF_HTML_App ( _name, _resourcePath, _locale ) {
- this.__proto__ = NOF_HTML_App.prototype;
-
- if (_resourcePath == null || _resourcePath.length <= 0)
- _resourcePath = "resources/global";
-
- this.name = _name || "generic_nof_app";
- this.locale = (_locale != null) ? _locale: NOF.UTIL.DefaultLocale;
- this.mainWindow = null;
- this.resourcePath = _resourcePath;
- this.resourceProperties = null;
-
- this.overridingResourcePath = null;
- this.overridingResouceProperties = null;
-
- this.disabledEvents = null;
- this.enabledEvents = null;
- this.areAllEnabled = true;
-
- this.stdErr = NOF.Global_ERR_ConsoleLogger;
- this.stdOut = NOF.Global_OUT_ConsoleLogger;
-
- //this.fsiApp = null;
- //this.fsiApp2 = null;
- }{
- var method = NOF_HTML_App.prototype;
-
- /**
- * Returns the name of the HTML application.
- **/
- method.getName = function (){ return this.name; }
-
- /**
- * Set the name for the HTML application.
- * @param name
- **/
- method.setName = function (/*String*/ name) { this.name = name; }
-
- /**
- * Returns the main editor (window) of the HTML application.
- **/
- method.getMainWindow = function (){ return this.mainWindow; }
- /**
- * Set the main editor (window) for the HTML application.
- * @param mainWindow
- **/
- method.setMainWindow = function (/*NOF.HTML.Window*/ mainWindow) {
- if (mainWindow != null ){
- mainWindow.setApp( this );
- this.mainWindow = mainWindow;
- }
- }
-
- /**
- * Initialize the HTML application i.e. call the init method of the main window.
- **/
- method.init = function (){
- this.getMainWindow().init();
- }
-
- /**
- * Get the locale of the HTML application.
- **/
- method.getLocale = function (){ return this.locale; }
- /**
- * Set the locale for the HTML application.
- * @param locale
- **/
- method.setLocale = function (/*NOF.UTIL.Locale*/ locale) { this.locale = locale; }
-
- /**
- * Get the path to resource of the HTML application.
- **/
- method.getResourcePath = function (){ return this.resourcePath; }
- /**
- * Set the resource path for the HTML application.
- * @param resourcePath
- **/
- method.setResourcePath = function (/*String*/ resourcePath){ this.resourcePath = resourcePath; }
-
- method.getOverridingResourcePath = function (){ return this.overridingResourcePath; };
- method.setOverridingResourcePath = function (overridingResourcePath){
- this.overridingResourcePath = overridingResourcePath;
- this.overridingResourceProperties = null;
- this.getOverridingResource();
- }
- method.clearOverridingResource = function () {
- this.overridingResourceProperties = null;
- this.overridingResourcePath = null;
- }
- method.getOverridingResource = function (/*NOF.UTIL.Locale*/ locale) {
- if (this.overridingResourceProperties == null && this.overridingResourcePath != null) {
- if (locale == null) locale = this.locale;
- this.overridingResourceProperties = this.getResourceFromFile (this.overridingResourcePath, locale);
- if (this.overridingResourceProperties == null)
- this.overridingResourcePath = null;
- }
- return this.overridingResourceProperties;
- }
-
- /**
- * Get the associated resource of the HTML application.
- * @param locale
- * @return an instance of NOF.UTIL.PropertyResourceBundle
- **/
- method.getResource = function (/*NOF.UTIL.Locale*/ locale) {
- if (this.resourceProperties == null) {
- if (locale == null) locale = this.locale;
- this.resourceProperties = this.getResourceFromFile (this.resourcePath, locale);
- }
- return this.resourceProperties;
- }
-
- /**
- * Get the property value from the associated resource.
- * @param key - name of the property
- * @return property value as String or null if the resource does not contain the specified property
- **/
- method.getResourceProperty = function ( key ){
- if (this.overridingResourcePath != null) {
- try {
- var property = this.getOverridingResource().getProperty( key );
- if (property != null)
- return property;
- }catch (e) {}
- }
- return this.getResource().getProperty( key );
- }
-
- /**
- * Get a resource.
- * @param resourcePath - path to the resource file.
- * @param locale - NOF.UTIL.Locale object used to specify the details
- * for requested resource. If missing or null,
- * the value of current locale member variable is used.
- * @return a NOF.UTIL.PropertyResourceBundle object with pairs (key/value)
- * from the resource file as specified by the resourcePath.
- **/
- method.getResourceFromFile = function (resourcePath, locale) {
- if ( locale != null )
- return NOF.UTIL.ResourceBundle.getBundle(resourcePath, locale);
- else
- return NOF.UTIL.ResourceBundle.getBundle(resourcePath, this.locale);
- }
-
-
- /**
- * Forces the resource to be reloaded
- * @param newLocale.
- */
- method.reloadResource = function ( newLocale ) {
- this.locale = newLocale;
- this.resourceProperties = null;
- return this.getResource();
- }
-
- method.isMenuChangeEnabled = function () {
- return this.areAllEnabled;
- }
-
- method.isEventEnabled = function (_evt) {
- if (this.areAllEnabled)
- return true;
-
- if (this.enabledEvents != null)
- return this.enabledEvents.contains(_evt);
- if (this.disabledEvents != null)
- return !this.disabledEvents.contains(_evt);
- return false;
- }
-
- method.enableEvent = function (_evt) {
- if (this.areAllEnabled)
- return true;
-
- if (this.enabledEvents == null)
- this.enabledEvents = new NOF.UTIL.ArrayList();
- this.enabledEvents.add (_evt);
- if (this.disabledEvents != null) {
- var index = this.disabledEvents.getIndex(_evt);
- if (index != -1)
- this.disabledEvents.remove(index);
- }
- }
-
- method.disableEvent = function (_evt) {
- if (this.areAllEnabled)
- this.areAllEnabled = false;
-
- if (this.disabledEvents == null)
- this.disabledEvents = new NOF.UTIL.ArrayList();
- this.disabledEvents.add (_evt);
- if (this.enabledEvents != null) {
- var index = this.enabledEvents.getIndex(_evt);
- if (index != -1)
- this.enabledEvents.remove(index);
- }
- }
-
- method.enableAllEvents = function () {
- this.disabledEvents = null;
- this.enabledEvents = null;
- this.areAllEnabled = true;
- }
-
- method.disableAllEvents = function () {
- this.areAllEnabled = false;
- this.disabledEvents = null;
- this.enabledEvents = null;
- }
-
- /**
- * Now it always dispatches all events to MainWindow.action which decides
- * whether it belongs to itself or to its children.
- * @param evt name.
- */
- method.dispatchEvent = function ( _evt ) {
- if (_evt != null ) {
- var evtObj;
- if (typeof(_evt) != 'object'){//a simple string was passed convert it to an EventObject
- var source = (arguments.length > 1) ? arguments[1] : null;
- evtObj = new NOF.EventObject( _evt, source);
- }else{
- evtObj = _evt;
- }
- if (this.isEventEnabled(evtObj))
- return this.getMainWindow().action( evtObj );
- }
- return false;
- }
-
- method._dispatchEvent = method.dispatchEvent;
-
- method.toString = function () {
- return this.getName() + " { MainWindow:" + this.getMainWindow() + ";ResourceFile:" + this.resourcePath + ";Locale:" + this.getLocale() + "}";
- }
-
- method.getFSIApp = function (){
- return NOF.App.getFSIApp();
- }
-
- method.getFSIApp2 = function (){
- return NOF.App.getFSIApp2();
- }
-
- /**
- * Set window title in NOF fashion. Call it before anything else.
- * @param title
- **/
- method.setTitle = function (/*String*/ title) {
- this.getFSIApp2().SetDialogTitle(this.getResourceProperty(title));
- }
-
-
- method.getStdErr = function (){ return this.stdErr; };
- method.setStdErr = function ( _stdErr ){ this.stdErr = _stdErr; };
-
- method.getStdOut = function (){ return this.stdOut; };
- method.setStdOut = function ( _stdOut ){ this.stdOut = _stdOut; };
-
- method.TRACE = function ( msg ){ /*this.stdOut.info( msg )*/ };
- method.ERROR = function ( msg ){ /*this.stdOut.severe( msg )*/ };
-
- }
-
- //NOF.__proto__.HtmlApp = NOF_HTML_App; //namespace
- HTML.__proto__.App = NOF_HTML_App;
- //NOF.addVariable("AppInstance", new NOF_HTML_App());
- NOF.addVariable("HTML.AppInstance", new NOF_HTML_App());
- }
-